package CtrLayer;
import ModelLayer.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;


/**
 * Write a description of class CustomerCtr here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CustomerCtr
{

    /**
     * Constructor for objects of class CustomerCtr
     */
    public CustomerCtr()
    {

    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public String add_customer(String name, String phone_nr, String address, String postal_code, String city, String group)
    {
        return CustomerCollection.add_customer(name, phone_nr, address, postal_code, city, group);
    }
    
     public boolean delete_customer(String id)
    {
        return CustomerCollection.delete_customer(id);
    }
    
     public boolean existing_customer(String id)
    {
        return CustomerCollection.existing_customer(id);
    }
    
    public String view_customer(String id)
    {
        return CustomerCollection.find_customer(id).printable();
    }
    
    public boolean update_customer(String id, String name, String phone_nr, String address, String postal_code, String city, String group)
    {
       return CustomerCollection.update_customer(id,name,phone_nr,address,postal_code,city,group);
    }
    
    public boolean is_group(String name)
    {
        return CustomerCollection.is_group(name);
    }
    
    public boolean is_group_used(String name)
    {
        return CustomerCollection.is_group_used(name);
    }
    
    public boolean add_group(String name,String terms, double discount)
    {
        return CustomerCollection.add_group(name,terms,discount);
    }
    
    public String find_group(String name)
    {
        return CustomerCollection.view_group(name);
    }
    
    public boolean update_group(String name, String terms, double discount)
    {
        return CustomerCollection.update_group(name,terms,discount);
    }
    
    public boolean delete_group(String name)
    {
        return CustomerCollection.delete_group(name);
    }
    
    public String print_groups()
    {
        String all = "";
        Iterator<Map.Entry<String, Group>> new_it = CustomerCollection.get_customer_groups().entrySet().iterator();       
        while (new_it.hasNext())
        {
            all=all.concat(CustomerCollection.view_group(new_it.next().getKey()));
            all=all.concat("\n\n");
        }
        return all;
    }
    
    public boolean existing_groups()
    {
        return CustomerCollection.get_customer_groups().isEmpty();
    }
    
    public void save_data()
    {
        CustomerCollection.save_all_data();
    }
}
